<?php
    /*
     * This example demonstrates how to add a known, registered mixin. 
     *
     * An extended object can add a known mixin by supplying the registered
     * mixin key as a parameter to the __addExtension() method.  If the 
     * mixin key is not valid, the method will throw a corresponding 
     * exception of ClassStructure_Exception_RegisteredExtensionDoesNotExist.
     *
     * @author Walter Badillo
     */
     
    require dirname(__FILE__) . DIRECTORY_SEPARATOR . '_include.php';
    
    try {
        
        $obj = new ClassStructure_Mixin_Delegator();
        
        echo "Test: Add a registered mixin" . "\n";
        echo '---------------------------------------------------------' . "\n\n";
        
        try {
            
            // The mixin key 'property' is registered, so this will work:
            $obj->__addMixin('property');

            echo 'ClassStructure_Property::setProperty' . "\n";
            $obj->property__setProperty('one', 1);
            $mix = $obj->property__getProperty('one');
            echo '  - set property named [one] with the value [' . $mix . '].' . "\n";
        
        } catch (ClassStructure_Exception_RegisteredMixinDoesNotExist $obj_exception) {
            echo 'ClassStructure_Exception_RegisteredMixinDoesNotExist' . "\n";
            echo '  - ' . $obj_exception->getMessage() . "\n";
        }
        
        echo "\n";
        
        echo "Test: Add an mixin which has not yet been registered" . "\n";
        echo '---------------------------------------------------------' . "\n\n";
        
        try {
            
            // The mixin key 'log' has not yet been registered, so this will not work:
            $obj->__addMixin('log');
            
            echo 'Log Mixin:' . "\n";
            $obj->log__logEvent('log message');
        
        } catch (ClassStructure_Exception_RegisteredMixinDoesNotExist $obj_exception) {
            echo 'ClassStructure_Exception_RegisteredMixinDoesNotExist' . "\n";
            echo '  - ' . $obj_exception->getMessage() . "\n";
        }
        
        echo "\n\n";
        
        //----------------------------------------------------------------------
        // Expose structure
        
        echo ClassStructure_UtilityFunctions::getObjectSignature($obj);
        
    } catch (Exception $obj_exception) {
        print_r($obj_exception);
    }
    
